package com.demo.controller.mine;

import com.demo.beans.ReturnData;
import com.demo.beans.User;
import com.demo.controller.BaseAction;
import com.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * @author 文皓
     * @date 2022/7/1 9:28
     * @desc 登录功能
     */
    @RequestMapping("register")
    public ReturnData userRegister(@RequestParam("nickname") String nickname, @RequestParam("password") String password, @RequestParam("phonenumber") String phonenumber, HttpServletRequest request) throws Exception{
        User user = new User();
        user.setNickName(nickname);
        user.setPassword(password);
        user.setPhoneNumber(phonenumber);
        return userService.userRegister(user,request);
    }

    /**
     * @author 文皓
     * @date 2022/7/4 9:17
     * @desc 登录
     */
    @RequestMapping("login")
    public ReturnData userLogin(@RequestParam("condition") String condition, @RequestParam("password") String password) throws Exception {
        Map<String,String> params = new HashMap<>();
        params.put("condition",condition);
        params.put("password",password);
        ReturnData returnData = userService.userLogin(params);
        return returnData;
    }

    /**
     * @author 文皓
     * @date 2022/7/17 8:59
     * @desc 获取用户列表
     */
    @RequestMapping("userList")
    public ReturnData userList(@RequestBody User user){
        ReturnData returnData = userService.userList(user);
        return returnData;
    }

    /**
     * @author 文皓
     * @date 2022/7/23 22:27
     * @desc 修改用户账号状态
     */
    @RequestMapping("updateUserState")
    public ReturnData updateUserState(@RequestBody User user){
        ReturnData returnData = userService.updateUserState(user);
        return returnData;
    }
}
